package com.hbzhit.modules.sys.controller;

import com.hbzhit.common.utils.PageUtils;
import com.hbzhit.common.utils.R;
import com.hbzhit.modules.sys.entity.SysDictEntity;
import com.hbzhit.modules.sys.service.SysDictService;
import com.hbzhit.modules.sys.vo.SysDictQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 数据字典
 *
 * @author DING
 * @date 2019-07-09 19:07:15
 */
@Api(tags = {"数据字典"})
@RestController
@RequestMapping("sys/dict")
public class SysDictController {
    @Autowired
    private SysDictService sysDictService;

    /**
     * 分页列表
     */
    @ApiOperation(value = "查询分页数据")
    @GetMapping("/page")
    public R<PageUtils<SysDictEntity>> page(SysDictQueryVO params){
        PageUtils<SysDictEntity> page = sysDictService.queryPage(params);

        return R.ok(page);
    }

    /**
     * 无分页列表
     */
    @ApiOperation(value = "查询列表数据")
    @GetMapping("/list")
    public R<List<SysDictEntity>> list(SysDictQueryVO params){
        List<SysDictEntity> list = sysDictService.queryList(params);

        return R.ok(list);
    }

    /**
     * 信息
     */
    @ApiOperation(value = "根据ID查询详细数据")
    @GetMapping("/info/{id}")
    public R<SysDictEntity> info(@PathVariable("id") Long id){
        SysDictEntity sysDict = sysDictService.getById(id);

        return R.ok(sysDict);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @PostMapping("/save")
    @RequiresPermissions("sys:dict:save")
    public R save(@RequestBody SysDictEntity sysDict){
        sysDictService.save(sysDict);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新数据")
    @PostMapping("/update")
    @RequiresPermissions("sys:dict:update")
    public R update(@RequestBody SysDictEntity sysDict){
        sysDictService.updateById(sysDict);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @PostMapping("/delete")
    @RequiresPermissions("sys:dict:delete")
    public R delete(@RequestBody Long[] ids){
        sysDictService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
